ViewSourceDialog.java


/*
    Rob Mayfield. IMSI @1997
    This creates a dialog which contains a text window and scrollbars.
    The text window uses a small subset of HTML to display multiple color
    in the text. This is done in the displayText class.
*/

import java.awt.*;
import textDisplay;

public class ViewSourceDialog extends Dialog
{
	public ViewSourceDialog(Frame parent, boolean modal, String popUpString)
	{

	    super(parent, modal);
  	    dHeight = 305; dWidth = 405;
		setLayout(null);
		addNotify();
		resize(insets().left + insets().right + dWidth,insets().top + insets().bottom + dHeight);
		setBackground(new Color(15790320));

		buttonPanel = new java.awt.Panel();
		//buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
        buttonPanel.setLayout(null);
		buttonPanel.reshape(insets().left , insets().top + 0, size().width - insets().left - insets().right - 5, 31);
		buttonPanel.setBackground(new Color(15790320));
		add(buttonPanel);

		buttonExit = new java.awt.Button("Exit");
		//buttonExit.reshape(271,5,36,21);
        buttonExit.reshape((buttonPanel.size().width/2)-18, 5,36,21);
		buttonPanel.add(buttonExit);

		textDisp = new textDisplay();
		textDisp.reshape(insets().left + 10, insets().top + 31, size().width - 18 - 15, size().height - insets().top - 31 - 15 - insets().bottom);  // 576, 360
		textDisp.setBackground(new Color(15790320));
		// set the text for the popup help
        textDisp.setText(popUpString);
		add(textDisp);

        // NOTE: scroll bars should be moved to the textDisplay Class
        // The scrollbars are instanciated with 0 initial position, thumb size of 10, min of 0 max of 99 
		verticalScrollbar = new java.awt.Scrollbar(Scrollbar.VERTICAL, 0, 10, 0, 250);
		verticalScrollbar.reshape(size().width - (insets().left*2) - 11, insets().top + 31, 15, size().height - insets().top - 31 - 16 -insets().bottom);  // 578 , 360
		//verticalScrollbar.setBackground(new Color(15790320));
        verticalScrollbar.setLineIncrement(1);
        verticalScrollbar.setPageIncrement(25);
		add(verticalScrollbar);

        // The scrollbars are instanciated with 0 initial position, thumb size of 6 (different length from verticle), min of 0 max of 99
		horizontalScrollbar = new java.awt.Scrollbar(Scrollbar.HORIZONTAL, 0, 6, 0, 250);
		horizontalScrollbar.reshape(insets().left, size().height - 16 - insets().bottom, size().width - 10 - (insets().left*2) - 5, 15);
        horizontalScrollbar.setLineIncrement(1);
        horizontalScrollbar.setPageIncrement(25);
		add(horizontalScrollbar);

		setTitle("Source Viewer");
		//textDisp = new textDisplay("This is a <br>longer test<br> string which make <FONT color="#FFFF00">for viewing tests<br>");
		//buttonPanel.reshape(insets().left , insets().top + 0, size().width - insets().left - insets().right - 5, 31);
        //textDisp.reshape(insets().left + 10, insets().top + 31, size().width - 18 - 15, size().height - insets().top - 31 - 15 - insets().bottom);  // 576, 360
        //verticalScrollbar.reshape(size().width - (insets().left*2) - 11, insets().top + 31, 15, size().height - insets().top - 31 - 16 -insets().bottom);  // 578 , 360
		//horizontalScrollbar.reshape(insets().left, size().height - 16 - insets().bottom, size().width - 10 - (insets().left*2) - 5, 15);
		Dim = new Dimension (size().width, size().height);
	}

	public ViewSourceDialog(Frame parent, String title, boolean modal)
	{
	    this(parent, modal, (String)null);
	    setTitle(title);
	}
	
    public void paint(java.awt.Graphics g)
    {
   		if ((Dim.width != size().width) || (Dim.height != size().height))
   		{
    		buttonPanel.reshape(insets().left , insets().top + 0, size().width - insets().left - insets().right - 5, 31);
            buttonExit.reshape((buttonPanel.size().width/2)-18, 5,36,21);
            textDisp.reshape(insets().left + 10, insets().top + 31, size().width - 18 - 15, size().height - insets().top - 31 - 15 - insets().bottom);  // 576, 360
            verticalScrollbar.reshape(size().width - (insets().left*2) - 11, insets().top + 31, 15, size().height - insets().top - 31 - 16 -insets().bottom);  // 578 , 360
    		horizontalScrollbar.reshape(insets().left, size().height - 16 - insets().bottom, size().width - 10 - (insets().left*2) - 5, 15);    
		}
    }

    public synchronized void show()
    {
    	Rectangle bounds = getParent().bounds();
    	Rectangle abounds = bounds();
    	// center window over parent
    	move(bounds.x + (bounds.width - abounds.width)/ 2,
    	     bounds.y + (bounds.height - abounds.height)/2);

    	super.show();
    }

	public boolean handleEvent(Event event)
	{
	    if(event.id == Event.WINDOW_DESTROY)
	    {
	        hide();
	        return true;
	    }
	    if (event.target == buttonExit && event.id == Event.ACTION_EVENT)
	    {
	        dispose();
	        return true;
	    }

        if (event.target == verticalScrollbar && event.id == Event.SCROLL_ABSOLUTE) 
        {
//System.out.println(event.toString());
			textDisp.verticalScrollbarAction(Event.SCROLL_ABSOLUTE, event.arg);
			return true;
		}

        // Handle scrollbar events  NOTE: scrollbars should be move to textDispaly class
		if (event.target == verticalScrollbar && event.id == Event.SCROLL_LINE_UP) 
        {
			textDisp.verticalScrollbarAction(Event.SCROLL_LINE_UP, event.arg);
			return true;
		}

        if (event.target == verticalScrollbar && event.id == Event.SCROLL_LINE_DOWN) 
        {
			textDisp.verticalScrollbarAction(Event.SCROLL_LINE_DOWN, event.arg);
			return true;
		}

        if (event.target == verticalScrollbar && event.id == Event.SCROLL_PAGE_UP) 
        {
			textDisp.verticalScrollbarAction(Event.SCROLL_PAGE_UP, event.arg);
			return true;
		}

        if (event.target == verticalScrollbar && event.id == Event.SCROLL_PAGE_DOWN) 
        {
			textDisp.verticalScrollbarAction(Event.SCROLL_PAGE_DOWN, event.arg);
			return true;
		}


		if (event.target == horizontalScrollbar && event.id == Event.SCROLL_LINE_UP) 
        {
			textDisp.horizontalScrollbarAction(Event.SCROLL_LINE_UP, event.arg);
			return true;
		}

        if (event.target == horizontalScrollbar && event.id == Event.SCROLL_LINE_DOWN) 
        {
			textDisp.horizontalScrollbarAction(Event.SCROLL_LINE_DOWN, event.arg);
			return true;
		}

        if (event.target == horizontalScrollbar && event.id == Event.SCROLL_PAGE_UP) 
        {
			textDisp.horizontalScrollbarAction(Event.SCROLL_PAGE_UP, event.arg);
			return true;
		}

        if (event.target == horizontalScrollbar && event.id == Event.SCROLL_PAGE_DOWN) 
        {
			textDisp.horizontalScrollbarAction(Event.SCROLL_PAGE_DOWN, event.arg);
			return true;
		}

        if (event.target == horizontalScrollbar && event.id == Event.SCROLL_ABSOLUTE) 
        {
//System.out.println(event.toString());
			textDisp.horizontalScrollbarAction(Event.SCROLL_ABSOLUTE, event.arg);
			return true;
		}

        return super.handleEvent(event);
	}

	java.awt.Panel buttonPanel;
	java.awt.Button buttonExit;
	java.awt.Scrollbar verticalScrollbar;
	java.awt.Scrollbar horizontalScrollbar;
	textDisplay textDisp;	
	Dimension Dim;
	int dHeight, dWidth;
}

SDK Top API Reference TurboCAD Home Page TurboCAD Programming Forums